/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package doc2db.interfaces.mainWindow;

import doc2db.interfaces.action.ShowTableAction;
import javax.swing.JEditorPane;
import javax.swing.event.HyperlinkEvent;
import javax.swing.event.HyperlinkListener;

/**
 *
 * @author yura
 */
public class MyHyperlinkListener implements HyperlinkListener{
    private JEditorPane textDBSelects = new JEditorPane();
    private MyJEditorPane textWeekendInformation = null;

    public MyHyperlinkListener(JEditorPane dBSelects, MyJEditorPane weekendInformation){
        this.textDBSelects = dBSelects;
        this.textWeekendInformation = weekendInformation;
    }

    public void hyperlinkUpdate(HyperlinkEvent e) {
        if (e.getEventType() == HyperlinkEvent.EventType.ENTERED) {
            textWeekendInformation.isOnHyperLink = true;
            textWeekendInformation.HyperLinkName = "" + e.getDescription();
        }
        if (e.getEventType() == HyperlinkEvent.EventType.EXITED) {
            textWeekendInformation.isOnHyperLink = false;
            textWeekendInformation.HyperLinkName = "" + "__NULL";
        }
        if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
            if (!textWeekendInformation.isInTable) {
                ShowTableAction showTableAction = new ShowTableAction(
                        textWeekendInformation, textDBSelects);
                //showTableAction.setRes(e.getDescription());
                int w = Integer.parseInt(e.getDescription().split(":")[0]);
                int h = Integer.parseInt(e.getDescription().split(":")[1]);
                showTableAction.setRes(textWeekendInformation.table[w][h]);
                showTableAction.actionPerformed(null);
            } else {
            }
        }
    }

}